<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()

// 需要确保组件定义了 name 属性
const keepAliveComponents = computed(() => {
  return route.matched
    .filter(item => item.meta?.keepAlive)
    .map(item => item.components?.default?.name)
    .filter(Boolean)
})
</script>

<template>
  <div class="app">
    <router-view v-slot="{ Component }">
      <keep-alive :include="keepAliveComponents">
        <component :is="Component" />
      </keep-alive>
    </router-view>
  </div>
</template>

<style lang="scss">
/* 重置样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  min-height: 100vh;
}

/* nprogress 样式覆盖 */
#nprogress .bar {
  background: #42b983 !important;
}

#nprogress .spinner-icon {
  border-top-color: #42b983 !important;
  border-left-color: #42b983 !important;
}

.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
